/**
 * Name: Fixed Menu Javascript.
 * Author: RYAN
 * Date: 16/4/20
 * URL: https://git.oschina.net/xpmer/FixedMenu
 */
window.onload = quoteCss;
window.onresize = setBgSize;
//引入样式文件
function quoteCss(){
    var headDom = document.getElementsByTagName("head")[0];
    var mainStyle = document.createElement("link");
    mainStyle.setAttribute("type","text/css");
    mainStyle.setAttribute("rel","stylesheet");
    mainStyle.setAttribute("href","stylesheets/commonJavascript.css");
    headDom.appendChild(mainStyle);
    insertMenuBtn();
}
//插入菜单按钮
var insterMenuBtnStatus = true;
/**
 * 插入菜单按钮
 */
function insertMenuBtn(){
    var menuA = document.createElement("a");
    menuA.href = "#";
    menuA.className = "yx-common-menu active animated wobble";
    var menuImg = document.createElement("img");
    menuImg.src = "stylesheets/imgs/Menu.png";
    menuA.onclick = function(){
        var yxBody = document.getElementsByClassName("yx-common-background")[0];
        if(insterMenuBtnStatus){
            yxBody.style.display = "block";
            yxBody.className = "yx-common-background animated fadeIn";
            menuImg.src = "stylesheets/imgs/CloseMenu.png";
            insterMenuBtnStatus = false
        }else{
            yxBody.className = "yx-common-background animated fadeOut";
            menuImg.src = "stylesheets/imgs/Menu.png";
            insterMenuBtnStatus = true;
        }
    }
    menuA.appendChild(menuImg);
    var bodyDom = document.getElementsByTagName("body")[0];
    bodyDom.appendChild(menuA);

    insertMenuBody( setBgSize );
}
/**
 * 插入菜单栏主体内容,并添加生成后的毁掉函数
 * @param callback
 */
function insertMenuBody( callback ){

    //容器
    var div_ele = document.createElement("div");
    div_ele.className = "yx-common-background";
    div_ele.style.display = 'none';

    //logo
    var logo_ele = document.createElement("div");
    logo_ele.className = "yx-common-logo";
    var logo_img_ele = document.createElement("img");
    logo_img_ele.src = "stylesheets/imgs/logo.png";
    logo_ele.appendChild(logo_img_ele);

    //desc
    var p_ele = document.createElement("p");
    p_ele.className = "yx-common-info";
    p_ele.innerText = "影集使用 「印象」 进行创作";

    //ucan
    var h2_ele = document.createElement("h2");
    h2_ele.className = "yx-common-ucan";
    h2_ele.innerText = "您也可以:";

    //list
    var list_ele = document.createElement("ul");
    list_ele.className = "yx-common-list";

    var li_ele = document.createElement("li");
    var a_ele = document.createElement("a");
    a_ele.innerText = "采用印象创建属于您的影集；";
    a_ele.href = "javascript:alert('待定')";
    li_ele.appendChild(a_ele);
    list_ele.appendChild(li_ele);

    var li_ele_2 = document.createElement("li");
    var a_ele_2 = document.createElement("a");
    a_ele_2.innerText = "欣赏该用户的更多精彩影集；";
    a_ele_2.href = "javascript:alert('待定')";
    li_ele_2.appendChild(a_ele_2);
    list_ele.appendChild(li_ele_2);

    var li_ele_3 = document.createElement("li");
    var a_ele_3 = document.createElement("a");
    a_ele_3.innerText = "用印象记录生活的点点滴滴；";
    a_ele_3.href = "javascript:alert('待定')";
    li_ele_3.appendChild(a_ele_3);
    list_ele.appendChild(li_ele_3);

    var li_ele_4 = document.createElement("li");
    var a_ele_4 = document.createElement("a");
    a_ele_4.innerText = "将美妙记忆分享到世界各地。";
    a_ele_4.href = "javascript:alert('待定')";
    li_ele_4.appendChild(a_ele_4);
    list_ele.appendChild(li_ele_4);

    //more
    var more_ele = document.createElement("div");
    more_ele.className = "yx-common-more";
    var more_a_ele = document.createElement("a");
    more_a_ele.href = "http://elian.engine.studio/";
    more_a_ele.innerText = "访问印象官网了解更多信息";
    more_ele.appendChild(more_a_ele);

    div_ele.appendChild(logo_ele);
    div_ele.appendChild(p_ele);
    div_ele.appendChild(h2_ele);
    div_ele.appendChild(list_ele);
    div_ele.appendChild(more_ele);

    var bodyDom = document.getElementsByTagName("body")[0];
    bodyDom.appendChild(div_ele);

    callback();
}
//设置背景尺寸
function setBgSize(){
    var bg = document.getElementsByClassName("yx-common-background")[0];
    bg.style.width = window.innerWidth + 'px';
    bg.style.height = window.innerHeight + 'px';
}